﻿using mqtt.client.test.Mqtt;
using mqtt.client.test.Mqtt.Connect;
using mqtt.client.test.Mqtt.Constant;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XjjXmm.Infrastructure.Common;
using XjjXmm.Infrastructure.Exceptions;

namespace mqtt.client.test.Output;

internal class SubscribeOutput
{
    private readonly ArraySegment<byte> buffer;

    public SubscribeOutput(ArraySegment<byte> buffer)
    {
        this.buffer = buffer;
    }

    public Response<string> Result()
    {
        // Get the return code from the buffer
        var returnCode = buffer[4];
        // Switch on the return code
        switch (returnCode)
        {
            // If the return code is 0, return
            case 0:
                return new Response<string>("");
            // If the return code is 0x01, return
            case 0x01:
                return new Response<string>("");
            // If the return code is 0x02, return
            case 0x02:
                return new Response<string>("");
            // If the return code is 0x80, throw an exception
            case 0x80:
                return new Response<string>("Failure 失败");
            // If the return code is not 0, throw an exception
            default:
                return new Response<string>("未知异常");
        }
    }


}
